<?php
    include('header.php');
    
    $sql = "SELECT * FROM patents_award ORDER BY pa_title";
    $result = $db->Execute($sql);
    $i = 1;
    $docs_list = '';
    while (!$result->EOF)
    {
        if(($i++)%2){
            $tr_class = 'even';
        }else{
            $tr_class = 'odd';
        }
        
        if(img_exists(APPPATH.'/files/patents-award',$result->fields['pa_path'])){
            $doc = '<a href="'.SITEURL.'/files/patents-award/'.$result->fields['pa_path'].'" target="_blank">'.$result->fields['pa_path'].'</a>';
        }else{
            $doc = 'ไม่มีไฟล์';
        }
        
        if($result->fields['pa_active']==1){
            $p_active = '<a href="?m=patents-award&s=patents-award-status_query&pa_id='.$result->fields['pa_id'].'" title="ไม่แสดง"><img src="images/apply.png" class="action_img" /></a>';
        }else{
            $p_active = '<a href="?m=patents-award&s=patents-award-status_query&pa_id='.$result->fields['pa_id'].'" title="แสดง"><img src="images/gg_ignored.png" class="action_img" /></a>';
        }
        
        $docs_list .=<<<packing_list
            <tr class="{$tr_class}">
                <td class="text_middle">{$result->fields['pa_title']}</td>
                <td class="text_center">{$doc}</td>
                <td class="text_center text_middle" style="width:130px;">{$p_active} / <a href="?m=patents-award&s=patents-award-edit&pa_id={$result->fields['pa_id']}" title="แก้ไข"><img src="images/edit.png" class="action_img" /></a> / <a href="javascript:delete_patents_award({$result->fields['pa_id']})" title="ลบ"><img src="images/delete.png" class="action_img" /></a></td>
            </tr>
packing_list;
        
        $result->MoveNext();
    }
    $result->Close();
    
?>
    <div class="grid_24" id="contents">
        
        <div id="contents_">
            
            <div id="add-from-link"><a href="?m=patents-award&s=patents-award-add" title="Add News">เพิ่ม Patents &amp; Award <img src="images/add.png" /></a></div>
            
            <table class="tb_list">
                <tr class="tr_header">
                    <th>ชื่อ</th>
                    <th>ไฟล์</th>
                    <th style="width:130px;">แสดง / แก้ไข / ลบ</th>
                </tr>
                <?php echo $docs_list; ?>
            </table>
            
        </div>
        
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script>
    function delete_patents_award(pa_id){
        if(confirm('ต้องการลบข้อมูล?')){
            window.location = '?m=patents-award&s=patents-award-delete_query&pa_id='+pa_id;
        }
    }
</script>